# -*- coding: utf-8 -*-
"""
Created on 2023-07-04 14:29
---------
@summary: 爬虫入口
---------
@author: pepsi
"""
from typing import Any


class Resp:
    def __init__(
            self,
            message: str = "",
            data: Any = None
    ):
        pass

    @property
    def to_dict(self):
        results = {}
        for key, value in self.__dict__.items():
            if key not in (
                    "__name__",
                    "__table_name__",
                    "__name_underline__",
                    "__update_key__",
                    "__unique_key__",
            ):
                if key.startswith(f"_{self.__class__.__name__}"):
                    key = key.replace(f"_{self.__class__.__name__}", "")
                results[key] = value

        return results


class OkResp(Resp):

    def __init__(
            self,
            message: str = "操作成功",
            data: Any = None
    ):
        super().__init__(message, data)
        self.err_no = 0
        self.message = message
        self.data = data


class FailResp(Resp):

    def __init__(
            self,
            message: str = "操作失败",
            data: Any = None
    ):
        super().__init__(message, data)
        self.err_no = 1
        self.message = message
        self.data = data
